package cn.wei.sdd.core.controller.admin;

import cn.wei.common.result.R;
import cn.wei.sdd.base.util.JwtUtils;
import cn.wei.sdd.core.pojo.entity.ServiceArea;
import cn.wei.sdd.core.pojo.vo.ServiceAreaVO;
import cn.wei.sdd.core.service.ServiceAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 服务区域表 前端控制器
 * </p>
 *
 * @author Wei
 * @since 2021-11-21
 */
@RestController
@Api(tags = "服务区域经纬度管理")
@RequestMapping("/admin/core/serviceArea")
public class AdminServiceAreaController {
    @Resource
    private ServiceAreaService serviceAreaService;

    @ApiOperation("获取服务区域经纬度list")
    @GetMapping("getServiceAreaList")
    public R getServiceAreaList(){
        List<ServiceAreaVO> list = serviceAreaService.listVO();
        return R.ok().data("list",list);
    }

    @ApiOperation("更新服务区域")
    @PostMapping("updateServiceArea")
    public R updateServiceArea(@RequestBody List<ServiceAreaVO> areaVOList, HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        serviceAreaService.updateServiceArea(areaVOList,userId);
        return R.ok().message("更新成功");
    }

}

